@extends('admin.layout')

@section('title', '编辑菜品')
@section('page-title', '编辑菜品')

@section('content')
<div class="space-y-6">
    <!-- 返回按钮 -->
    <div class="flex items-center">
        <a href="{{ route('admin.dishes.index') }}" 
           class="inline-flex items-center text-sm font-medium text-gray-500 hover:text-gray-700">
            <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
            </svg>
            返回菜品列表
        </a>
    </div>

    <!-- 编辑菜品表单 -->
    <div class="bg-white shadow-lg rounded-xl border border-gray-100">
        <div class="px-6 py-6 border-b border-gray-200">
            <div class="flex items-center">
                <svg class="w-6 h-6 text-indigo-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
                </svg>
                <h2 class="text-xl font-semibold text-gray-900">编辑菜品</h2>
            </div>
            <p class="mt-2 text-sm text-gray-600">修改菜品的基本信息</p>
        </div>

        <form method="POST" action="{{ route('admin.dishes.update', $dish->id) }}" class="px-6 py-6">
            @csrf
            @method('PUT')
            
            <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">
                <!-- 菜品名称 -->
                <div class="sm:col-span-2">
                    <label for="name" class="block text-sm font-medium text-gray-700">
                        菜品名称 <span class="text-red-500">*</span>
                    </label>
                    <div class="mt-1">
                        <input type="text" 
                               name="name" 
                               id="name"
                               value="{{ old('name', $dish->name) }}"
                               required
                               class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('name') border-red-300 @enderror">
                    </div>
                    @error('name')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 菜品描述 -->
                <div class="sm:col-span-2">
                    <label for="description" class="block text-sm font-medium text-gray-700">
                        菜品描述 <span class="text-red-500">*</span>
                    </label>
                    <div class="mt-1">
                        <textarea name="description" 
                                  id="description"
                                  rows="3"
                                  required
                                  class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('description') border-red-300 @enderror">{{ old('description', $dish->description) }}</textarea>
                    </div>
                    @error('description')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 分类选择 -->
                <div>
                    <label for="category_id" class="block text-sm font-medium text-gray-700">
                        菜品分类 <span class="text-red-500">*</span>
                    </label>
                    <div class="mt-1">
                        <select name="category_id" 
                                id="category_id"
                                required
                                class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('category_id') border-red-300 @enderror">
                            <option value="">请选择分类</option>
                            @foreach($categories as $category)
                                <option value="{{ $category->id }}" 
                                        {{ (old('category_id', $dish->category_id) == $category->id) ? 'selected' : '' }}>
                                    {{ $category->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    @error('category_id')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 排序 -->
                <div>
                    <label for="sort_order" class="block text-sm font-medium text-gray-700">排序</label>
                    <div class="mt-1">
                        <input type="number" 
                               name="sort_order" 
                               id="sort_order"
                               value="{{ old('sort_order', $dish->sort_order) }}"
                               min="0"
                               class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('sort_order') border-red-300 @enderror">
                    </div>
                    @error('sort_order')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 标签 -->
                <div>
                    <label for="tags" class="block text-sm font-medium text-gray-700">标签</label>
                    <div class="mt-1">
                        <input type="text" 
                               name="tags" 
                               id="tags"
                               value="{{ old('tags', is_array($dish->tags) ? implode(',', $dish->tags) : $dish->tags) }}"
                               placeholder="用逗号分隔多个标签，如：麻辣,经典,下饭"
                               class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('tags') border-red-300 @enderror">
                    </div>
                    <p class="mt-1 text-sm text-gray-500">用逗号分隔多个标签</p>
                    @error('tags')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 口味 -->
                <div>
                    <label for="flavors" class="block text-sm font-medium text-gray-700">口味</label>
                    <div class="mt-1">
                        <input type="text" 
                               name="flavors" 
                               id="flavors"
                               value="{{ old('flavors', is_array($dish->flavors) ? implode(',', $dish->flavors) : $dish->flavors) }}"
                               placeholder="用逗号分隔多个口味，如：麻辣,鲜香"
                               class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('flavors') border-red-300 @enderror">
                    </div>
                    <p class="mt-1 text-sm text-gray-500">用逗号分隔多个口味</p>
                    @error('flavors')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 烹饪时间 -->
                <div>
                    <label for="cooking_time" class="block text-sm font-medium text-gray-700">烹饪时间（分钟）</label>
                    <div class="mt-1">
                        <input type="number" 
                               name="cooking_time" 
                               id="cooking_time"
                               value="{{ old('cooking_time', $dish->cooking_time) }}"
                               min="1"
                               max="300"
                               class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('cooking_time') border-red-300 @enderror">
                    </div>
                    @error('cooking_time')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 状态设置 -->
                <div class="sm:col-span-2">
                    <div class="flex items-center space-x-6">
                        <div class="flex items-center">
                            <input type="checkbox" 
                                   name="is_featured" 
                                   id="is_featured"
                                   value="1"
                                   {{ old('is_featured', $dish->is_featured) ? 'checked' : '' }}
                                   class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">
                            <label for="is_featured" class="ml-2 block text-sm text-gray-900">
                                设为推荐菜品
                            </label>
                        </div>
                        <div class="flex items-center">
                            <input type="checkbox" 
                                   name="is_available" 
                                   id="is_available"
                                   value="1"
                                   {{ old('is_available', $dish->is_available) ? 'checked' : '' }}
                                   class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">
                            <label for="is_available" class="ml-2 block text-sm text-gray-900">
                                设为可用
                            </label>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 提交按钮 -->
            <div class="mt-8 flex justify-end space-x-3">
                <a href="{{ route('admin.dishes.index') }}" 
                   class="inline-flex items-center px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                    取消
                </a>
                <button type="submit" 
                        class="inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
                    </svg>
                    更新菜品
                </button>
            </div>
        </form>
    </div>
</div>
@endsection
